package ar.edu.unq.wannaplay.roles;

import java.io.Serializable;

import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.panel.EmptyPanel;
import org.apache.wicket.markup.html.panel.Panel;

import ar.edu.unq.wannaplay.dtos.ClientDTO;
import ar.edu.unq.wannaplay.dtos.EmployeeDTO;
import ar.edu.unq.wannaplay.dtos.ProjectDTO;
import ar.edu.unq.wannaplay.pages.Home;
import ar.edu.unq.wannaplay.panels.client.ClientViewPanel;
import ar.edu.unq.wannaplay.panels.employee.EmployeesViewPanel;
import ar.edu.unq.wannaplay.panels.links.NormalLinkPanel;
import ar.edu.unq.wannaplay.panels.project.ProjectsViewPanel;
import ar.edu.unq.wannaplay.services.UserService;
import ar.edu.unq.wannaplay.users.Role;
import ar.edu.unq.wannaplay.utils.ClientListView;
import ar.edu.unq.wannaplay.utils.EmployeeListView;
import ar.edu.unq.wannaplay.utils.ProjectsListView;

public abstract class AbstractLinkAdderStrategy implements Serializable {
    private static final long serialVersionUID = 1L;

    protected static final String LINK = "link";

    private static AbstractLinkAdderStrategy user;

    private UserService userService;

    public static void setLogedUser(final AbstractLinkAdderStrategy aUser) {
        user = aUser;
    }

    public static AbstractLinkAdderStrategy getUserLoged() {
        return user;
    }

    public abstract void addClientViewLinks(final ListItem<ClientDTO> item, final ClientListView view, Panel panel);

    public abstract void addClientCreateLinks(final ClientViewPanel aPanel);

    public abstract void addEmployeesViewLinks(final ListItem<EmployeeDTO> item, final EmployeeListView view,
            Panel panel);

    public abstract void addEmployeeCreateLink(final EmployeesViewPanel aPanel);

    public abstract void addProjectsViewLinks(final ListItem<ProjectDTO> item, final ProjectsListView view, Panel panel);

    public abstract void addProjectsCreateLink(final ProjectsViewPanel aPanel);

    public static void setUser(final UserService service, final Role role) {

        if (role.equals(Role.ADMIN)) {
            setLogedUser(new AdminLinkAdderStrategy());
        } else {
            setLogedUser(new RegularUserLinkAdderStrategy());
        }
        getUserLoged().setService(service);
    }

    private void setService(final UserService service) {
        userService = service;
    }

    public abstract void addHomeContent(Home home);

    public UserService getService() {
        return userService;
    }

    protected EmptyPanel hidingPanel(final String id) {
        return new EmptyPanel(id);
    }

    protected NormalLinkPanel createLinkPanel(final String id, final Link<?> link, final String property,
            final Panel aPanel) {
        return new NormalLinkPanel(id, link, this.fetchPanelMessage(aPanel, property));
    }

    public UserService getUserService() {
        return userService;
    }

    public void setUserService(final UserService userService) {
        this.userService = userService;
    }

    protected String fetchPanelMessage(final Panel panel, final String key) {
        return panel.getLocalizer().getString(key, panel);
    }

}
